/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name          : spi_flash.h
* Author             : MCD Application Team
* Version            : V2.0.3
* Date               : 09/22/2008
* Description        : Header for spi_flash.c file.
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __SPI_CC1101_H
#define __SPI_CC1101_H

/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_spi.h"
//#include "stm32f10x_exti.h"
#include "stm32f10x.h"
#include "misc.h"
//#include "nvic.h"
/****************************
 *PB10 ----- GDO0
 *PB12 ----- NSS
 *PB13 ----- SCK
 *PB15 ----- MOSI
 *PB14 ----- MISO
****************************/

typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;

#define INT8U  uint8
#define INT16U uint16

#define CC_SPI_MI_PORT       GPIOB
#define CC_SPI_MI_PIN        GPIO_Pin_14
#define CC_SPI_MO_PORT       GPIOB
#define CC_SPI_MO_PIN        GPIO_Pin_15
#define CC_SPI_SCK_PORT      GPIOB
#define CC_SPI_SCK_PIN       GPIO_Pin_13
#define CC_SPI_CS_PORT       GPIOB
#define CC_SPI_CS_PIN        GPIO_Pin_12
#define CC_GDO0_PORT         GPIOB
#define CC_GDO0_PIN          GPIO_Pin_10


#define CC_CSN_SELECT_ON()   GPIO_ResetBits( CC_SPI_CS_PORT, CC_SPI_CS_PIN )
#define CC_CSN_SELECT_OFF()  GPIO_SetBits( CC_SPI_CS_PORT, CC_SPI_CS_PIN )
#define CC_CSN_IS_OFF()      GPIO_ReadInputDataBit( CC_SPI_CS_PORT, CC_SPI_CS_PIN )

#define CC_MI_IS_HIGH()      GPIO_ReadInputDataBit( CC_SPI_MI_PORT, CC_SPI_MI_PIN )
#define CC_READ_MI()         CC_MI_IS_HIGH()

#define CC_GDO0_IS_HIGH()    GPIO_ReadInputDataBit( CC_GDO0_PORT, CC_GDO0_PIN )

//#define CC_SPI_WRITE_BYTE(x) SPI_SendData(CC_SPI, x)
//#define CC_SPI_READ_BYTE()   SPI_ReceiveData(CC_SPI)
//#define CC_SPI_WAIT_DONE()   while( SPI_GetFlagStatus( CC_SPI, SPI_FLAG_RXNE ) == RESET )


void CC_spiInit( void );//configure and GDO0
void CC_delay( uint32 nCount );
uint8 SPI_ExchangeByte( uint8 input );


#endif
